using System;
using System.Collections;
using System.Web.UI.WebControls;
using ITG.Modules.HR.Components;
using THANHTUNGO.Portal.Components.UI;

namespace ITG.Modules.HR.Controls
{
    public partial class Permissions : YAFPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            ArrayList selectedItems = new ArrayList();
            foreach (ListItem item in chkDepartment.Items)
            {
                if (item.Selected)
                {
                    selectedItems.Add(item.Value);
                }
            }
            string[] departments = (string[]) selectedItems.ToArray(typeof (string));
            Accessing.UpdateAccessing(Convert.ToInt32(ddlRole.SelectedValue), departments);
        }

        protected void ddlRole_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListItem item in chkDepartment.Items)
            {
                item.Selected = false;
            }

            string[] departments = Accessing.SelectDepartmentBy_RoleID(Convert.ToInt32(ddlRole.SelectedValue));
            foreach (ListItem item in chkDepartment.Items)
            {
                foreach (string d in departments)
                {
                    if (item.Value == d)
                    {
                        item.Selected = true;
                        break;
                    }
                }
            }
        }
    }
}